//
//  BaseCollectionViewController.m
//  OverseasOnlineShopping
//
//  Created by 唐先才 on 16/3/6.
//  Copyright © 2016年 唐先才. All rights reserved.
//

#import "BaseCollectionViewController.h"
#import "BaseCollectionViewCell.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#import "TxcPrefixHeader.pch"
#import "OverseasOnlineShopping-Swift.h"

@interface BaseCollectionViewController ()

@end

@implementation BaseCollectionViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.baseDataArray = [[NSMutableArray alloc] init];
    [self createCollectionView];
}

- (void)createCollectionView {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.baseCollectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    [self.view addSubview:self.baseCollectionView];
    self.baseCollectionView.backgroundColor = BACKCOLOR;
    self.baseCollectionView.dataSource = self;
    self.baseCollectionView.delegate = self;
    UINib *nib = [UINib nibWithNibName:@"BaseCollectionViewCell" bundle:[NSBundle mainBundle]];
    [self.baseCollectionView registerNib:nib forCellWithReuseIdentifier:@"baseCollectionViewCell"];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.baseDataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    return [BaseCollectionViewCell configCellWith:collectionView indexPath:indexPath dataArray: self.baseDataArray];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake((WIDTH - 20) / 2, 320);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(10, 5, 10, 5);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    TxcModel *model = self.baseDataArray[indexPath.row];
    DetailViewController *detailVC = [[DetailViewController alloc] init];
    NSString *infoID = [NSString stringWithFormat:@"%@", model.InfoID];
    detailVC.goodsID = infoID;
    detailVC.parameters = @{@"infoID": infoID};
    detailVC.pic_url = model.MainImage;
    [self.navigationController pushViewController:detailVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
